const path = require('path');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin');

module.exports = {
    // 入口文件
    entry: "./src/index.ts",
    // 打包文件
    output: {
        // 打包输出目录
        path: path.resolve(__dirname, "dist"),
        // 打包后文件名称
        filename: "hades_dialog.js",
        environment: {
            arrowFunction: false
        }
    },

    module: {
        rules: [
            {
                test: /\.ts$/,
                use: [
                    {
                        loader: "babel-loader",
                        options: {
                            presets: [
                                [
                                    "@babel/preset-env",
                                    {
                                        targets: {
                                            "chrome": "60",
                                            "ie": "9",
                                        },
                                        "corejs": "3",
                                        "useBuiltIns": "usage"
                                    }
                                ]
                            ]
                        }
                    },
                    'ts-loader'
                ],
                exclude: /node_modules/
            },
            {
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    "css-loader",
                    "postcss-loader",
                    "sass-loader"
                ],
            }
        ]
    },

    plugins: [
        new HTMLWebpackPlugin({
            template: "./public/index.html",
            scriptLoading: 'blocking',
            filename: 'test/index.html'
        }),
        new CleanWebpackPlugin(),
        new MiniCssExtractPlugin()
    ],

    resolve: {
        extensions: [".js", ".ts"]
    }
};
